<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class System extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
	}
	
	/**
	 * 还款
	 * @param $id
	 */
	function repay(){
		$this->load->model('System_model');
		$list = $this->System_model->borrow_repay();
		if(count($list) > 0){
			$this->load->model('Borrow_model');
			foreach($list as $obj){
				$data['repayment_id'] 	= $obj['id'];
				$data['user_id'] 		= $obj['user_id'];
				$data['ip'] 			= '127.0.0.1';
				$ret = $this->Borrow_model->repay($data);
				echo $obj['id'].'-'.$obj['user_id'].'='.$ret;
			}
		}
		echo "repay over";
	}
	
	/**
	 * 流转标还款
	 * @param $id
	 */
	function lzrepay(){
		$this->load->model('System_model');
		$list = $this->System_model->lzborrow_repay();
		if(count($list) > 0){
			$this->load->model('Borrow_model');
			foreach($list as $obj){
				$data['collection_id'] 	= $obj['id'];
				$data['user_id'] 		= $obj['user_id'];
				$data['ip'] 			= '127.0.0.1';
				$ret = $this->Borrow_model->lz_repay($data);
				//echo $obj['id'].'-'.$obj['user_id'].'='.$ret;
			}
			//回款后自动投30天的
//			$this->load->model('Yjb_model');
//			$this->load->model('Mydb_model','mydb');
//			$sql = "select id from ych_yjb_borrow where fstatus in(2,3,4) order by id desc limit 1";
//			$yjb = $this->mydb->query_sql($sql,'row');
//			$this->Yjb_model->yjb_auto_tender($yjb['id']);
		}
		echo "lzrepay over";
	}
	
	/*function testlzrepay(){
		$this->load->model('Borrow_model');
		$data['collection_id'] 	= 118186;
		$data['user_id'] 		= 329;
		$data['ip'] 			= '127.0.0.1';
		$ret = $this->Borrow_model->lz_repay($data);
		var_dump($ret);
	}*/
	
	/**
	 * 老版易居宝还款
	 */
	function slrepay(){
		$this->load->model('System_model');
		$list = $this->System_model->slborrow_repay();
		if(count($list) > 0){
			$this->load->model('Borrow_model');
			foreach($list as $obj){
				$data['collection_id'] 	= $obj['id'];
				$data['user_id'] 		= $obj['user_id'];
				$data['ip'] 			= '127.0.0.1';
				$ret = $this->Borrow_model->sl_repay($data);
				echo $obj['id'].'-'.$obj['user_id'].'='.$ret;
			}
		}
		echo "lzrepay over";
	}
	
	/**
	 * 新版易居宝还款
	 */
	function yjbrepay(){
		$this->load->model('Yjb_model');
		$this->Yjb_model->repay();
		
//		//回款后自动投30天的
//		$this->load->model('Mydb_model','mydb');
//		$sql = "select id from ych_yjb_borrow where fstatus in(2,3,4) order by id desc limit 1";
//		$yjb = $this->mydb->query_sql($sql,'row');
//		$this->Yjb_model->yjb_auto_tender($yjb['id']);
	}

	/**
	 * 流转标还款
	 * @param $id
	 */
	function liubiao(){
		$this->load->model('System_model');
		$list = $this->System_model->liubiao();
		if(count($list) > 0){
			$this->load->model('Borrow_model');
			foreach($list as $obj){
				$data['id'] 		= $obj['id'];
				$data['user_id'] 	= $obj['user_id'];
				$data['ip'] 		= $this->js->get_ip();
				echo $this->Borrow_model->Cancel($data);
			}
		}
		echo "liubiao over";
	}
}